﻿using System;
using Liber;
using Liber.SOA;
using Liber.ORM;
using Liber.BizTools;

namespace SoBusiness.App
{
    public class LogisticApp : SOAUnit
    {

        [API("NewDelivery")]
        FnResult<DyObject> NewDelivery(SOARequestContext cntx)
        {
            var data = cntx.RequestContext.GetOrDefault<DyObject>("dlvorder", null);
            var mx = data["items"] as List<DyObject>;
            if (mx == null || mx.Count == 0)
            {
                return FnResult<DyObject>.Failure(Name, "RequiredArgs").SetError("items", "empty delivery mx");
            }
            try
            {
                NewDeliveryOrder((long)data["orderid"], (DateTime)data["dlvarrival"], data["dlvorderno"].ToString(), data["deliverier"].ToString(), mx);
                return FnResult<DyObject>.Sucess(null);
            }
            catch (Exception ex)
            {
                return FnResult<DyObject>.Failure(Name, "NewDeliveryFailur").SetError("exception", ex.Message);
            }
        }

    }
}
